@shyamsundar-k said in How to generate and authorized java spring controller using JWT:
We need to pass the token in the API header as Authorization: Bearer<token> But what is the process so that I can validate the endpoint with the valid token if the token is invalid or does not have the required roles or scope then I should get 401 else I should be able to access the API successfully.
Once you have a token in your API, you can validate it in two different ways. But it's worth noting that to validate the token, you must validate the signature and then the claims.
First option: use a library to validate the signature. Most languages have options. For java, you can use fusionauth-jwt, the readme has sample code.
Second option: use the validate API. You could use the FusionAuth client library to make this call if you'd like.
The first means you have to pick a library. The second means you have to make a network call.
Either way, after you validate the signature, you need to check the claims (issuer, audience, expiration, custom claims) to make sure they are what you expect.
Here's more about how to consume a JWT.